package com.dqyt.app.mongo;

import com.dqyt.app.bean.Maintenance;
import com.dqyt.app.bean.OtherInput;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component;

import java.util.List;


@Component
public class OtherInputDao {


    /**
     * 注入MongoTemplate
     */
    @Autowired
    protected MongoTemplate mongoTemplate;


    /**
     * 新建数据到数据库
     *
     * @return
     */
    public void save(OtherInput otherInput) {
        mongoTemplate.save(otherInput); // 保存数据到数据库
    }

    public OtherInput getOtherInput(){
        // 构建查询条件
        Query query = new Query();
        List<OtherInput> list = mongoTemplate.find(query, OtherInput.class, OtherInput.TableName); // 取得满足条件的数据
        if(list.size()>0){
            return list.get(0);
        }else{
            return null;
        }
    }


}
